package com.yanqu.road.dataHelper.action;

import com.yanqu.road.dataHelper.action.excel.AddGoodsReource;
import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.manager.ServerMgr;
import com.yanqu.road.dataHelper.utils.ExcelData;
import com.yanqu.road.entity.servercenter.ServerInfo;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class AddGoodsResourceExcel extends actionBase {
    public void go(List<Long> serverList) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        List<Future> futureList = new ArrayList<>();
        String dirPath = System.getProperty("user.dir") + File.separator;
        ExcelData beautyExcel = new ExcelData(dirPath + "inExcel" + File.separator + "Beauty.xlsx", "Sheet1");
        ExcelData skinExcel = new ExcelData(dirPath + "inExcel" + File.separator + "SkinsInfo.xlsx", "Sheet1");
        Map<Integer, String> beautyResourceMap = new HashMap<>();
        for (Map.Entry<String, Map<String, String>> entry : beautyExcel.getExcelData().entrySet()) {
            Map<String, String> value = entry.getValue();
            String beautyId = value.get("id=int");
            String icon = value.get("icon=string");
            String sound = value.get("sound=string");
            String appearanceId = value.get("appearanceId=string");
            beautyResourceMap.put(Integer.valueOf(beautyId), icon + "&" + sound + "&" + appearanceId);
        }
        GameServer.getLogger().error("dataMap Size {}",beautyResourceMap.size());


        Map<Integer, String> skinResourceMap = new HashMap<>();
        for (Map.Entry<String, Map<String, String>> entry : skinExcel.getExcelData().entrySet()) {
            Map<String, String> value = entry.getValue();
            String beautyId = value.get("skinId=int");
            String icon = value.get("icon=string");
            String sound = value.get("sound=string");
            String appearanceId = value.get("appearanceId=string");
            skinResourceMap.put(Integer.valueOf(beautyId), icon + "&" + sound + "&" + appearanceId);
        }
        GameServer.getLogger().error("dataMap Size {}",skinResourceMap.size());


//        activityIdStr = "9888885";
        for (Long serverId : serverList) {
            if (ServerMgr.getServerInfoList().containsKey(serverId)) {
                ServerInfo serverInfo = ServerMgr.getServerInfoList().get(serverId);
                Future future = executorService.submit(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        GameServer testGameServer = new GameServer(serverInfo);
                        AddGoodsReource reource = new AddGoodsReource(testGameServer);
                        reource.go(serverId,beautyResourceMap,skinResourceMap);
                        return true;
                    }
                });
                futureList.add(future);
            }
        }
        isResult(futureList);
//            DataMgr.makeExcelData2Txt("");
//            DataMgr.outText("活动商城购买"+activityId);
        DataMgr.makeExcelData2Txt("");
        DataMgr.outText("活动商城购买");
    }
}
